listbox: Don't steal focus-on-click
authorMatthias Clasen <mclasen@redhat.com>
Wed, 13 May 2020 23:43:04 +0000 (19:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 13 May 2020 23:43:04 +0000 (19:43 -0400)
If a row has content that is focus-on-click, and is set
to focus-on-click itself, then the row steals the focus
fromt he content, since it uses focus-on-click on button
release, as opposed to button press. Avoid that by
refusing to take focus if it is already on some
descendent of the row.

This was showing up in the widget-factory listbox on
page 2, where clicking on the spinbutton would briefly
put the focus on the spinbutton, only to lose it to
the row.

gtk/gtklistbox.c

index 8e2c5409eace86b32876e7a1a8c4e29d86509eb7..bc4676566fd111527c3740396ffa88303d754e52 100644 (file)
@@ -1516,7 +1516,13 @@ gtk_list_box_update_cursor (GtkListBox    *box,
   box->cursor_row = row;
   ensure_row_visible (box, row);
   if (grab_focus)
-    gtk_widget_grab_focus (GTK_WIDGET (row));
+    {
+      GtkWidget *focus;
+
+      focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (box)));
+      if (!focus || !gtk_widget_is_ancestor (focus, GTK_WIDGET (row)))
+        gtk_widget_grab_focus (GTK_WIDGET (row));
+    }
   gtk_widget_queue_draw (GTK_WIDGET (row));
   _gtk_list_box_accessible_update_cursor (box, row);
 }